//
//  JSOrderEvaluaController.m
//  jshop
//
//  Created by 张艳江 on 2019/5/22.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCOrderEvaluaController.h"
#import "SCEvaluaCell.h"

@interface SCOrderEvaluaController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;

@end

@implementation SCOrderEvaluaController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title = @"订单评价";
    self.view.backgroundColor = BGColor;
    
    [self setUpTableView];
}
#pragma mark - 表格
- (void)setUpTableView{
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0.5, kScreenW, kScreenH - kTopHeight - 50) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = BGColor;
    self.tableView.rowHeight = 418;
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.tableFooterView = [[UIView alloc]init];
    // 注册
    [self.tableView registerNib:[UINib nibWithNibName:@"SCEvaluaCell" bundle:nil] forCellReuseIdentifier:@"SCEvaluaCellID"];
    [self.view addSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.goodsArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SCEvaluaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SCEvaluaCellID"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.goodsArray[indexPath.row];
    cell.vc = self;
    return cell;
}
#pragma mark - 点击提交
- (IBAction)clickSubmitBtn:(UIButton *)sender {
    

    NSMutableArray *dataArray = [NSMutableArray array];
    for (SCModel *model in self.goodsArray) {
        
        if (model.comment.length == 0 || model.upPicArray.count == 0) {
            [SVProgressHUD showImage:nil status:@"您还有信息未填写或者图片未上传"];
            return;
        }
        NSDictionary *dict = @{@"order_id":model.order_id,
                               @"score":model.score,
                               @"comment":model.comment,
                               @"pic":[model.upPicArray componentsJoinedByString:@","],
                               @"anonymous":model.anonymous,
                               @"deliver_score":model.deliver_score};
        [dataArray addObject:[dict mj_JSONString]];
    }
    
    NSString *dataString = [NSString stringWithFormat:@"[%@]",[[dataArray copy] componentsJoinedByString:@","]];
    NSDictionary *dict = @{@"type":self.type,
                           @"token":Token,
                           @"data":dataString};
    //NSLog(@"提交的数据%@",dict);
    NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=GiftAppOrder&a=App_evaluate_do"];
    [SVProgressHUD showWithStatus:@"提交中..."];
    [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
        [SVProgressHUD showSuccessWithStatus:@"评价成功"];
        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
    }];
}

@end
